package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class DeviceImageAdapter extends BaseRecycleAdapter<LocalMedia> {
    private ImageView photo_img;
    private TextView delete_tv;

    public DeviceImageAdapter(Context context, List<LocalMedia> datas) {
        super(context, R.layout.item_image_publish, datas);
    }

    @Override
    public void setDatas(List<LocalMedia> datas) {
        super.setDatas(datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final LocalMedia entity) {
        holder.setBinding(BR.viewModel, entity);
        photo_img = holder.itemView.findViewById(R.id.photo_img);
        delete_tv = holder.itemView.findViewById(R.id.delete_tv);
        Bitmap bitmap = BitmapFactory.decodeFile(entity.getRealPath());
        photo_img.setImageBitmap(bitmap);
        delete_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                removeItem(entity);
            }
        });
    }

}
